<%--
  Created by IntelliJ IDEA.
  User: MadFrog
  Date: 2017/6/20
  Time: 11:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>心理测试</title>
    <%@include file="../common/_head.jsp"%>
</head>
<body ontouchstart>
<%--<div class="weui-tab">--%>
    <%--<div class="weui-navbar">--%>
        <%--<a class="weui-navbar__item weui-bar__item--on" href="#tab-mental-undo">--%>
            <%--未完成的测试--%>
        <%--</a>--%>
        <%--<a class="weui-navbar__item" href="#tab-mental-done">--%>
            <%--已完成的测试--%>
        <%--</a>--%>
    <%--</div>--%>
    <%--<div class="weui-tab__bd">--%>
        <%--<div id="tab-mental-undo" class="weui-tab__bd-item weui-tab__bd-item--active">--%>
            <div class="weui-panel" id="panel-undo"></div>
        <%--</div>--%>
        <%--<div id="tab-mental-done" class="weui-tab__bd-item"></div>--%>
    <%--</div>--%>
<%--</div>--%>
<%@include file="../common/_foot.jsp"%>
<script type="text/javascript">
    $(function () {
        $.ajax({
            type: "get",
            url: "${ctx}/student/mental/listMentalByStudent",
            dataType: "json",
            success: function (re) {
                initUndo(re.data);
            },
            error: function () {
                $.toast("请完成当前题目", "cancel");
            }
        });
        function initUndo(mList) {
            // 渲染“未完成的测试”面板
            var undoPanel = $("#panel-undo");
            for (var i=0; i<mList.length; i++){
                var sm = mList[i];
                var fullDate = new Date(sm.closeDate);
                var operateStr;
                if(sm.finishStatus=="FINISHED"){
                    operateStr = "已完成";
                }else{
                    operateStr = "<a href=\"${ctx}/student/rubricIndex/" + sm.mental.id + "\">开始测试>></a>";
                }
                var closeDate = fullDate.getFullYear()+"-"+(fullDate.getMonth()+1)+"-"+fullDate.getDate();
                var mText =         "<div class=\"weui-media-box weui-media-box_text\">\n" +
                    "                    <h4 class=\"weui-media-box__title\">" + sm.mentalName + "</h4>\n" +
                    "                    <p class=\"weui-media-box__desc\">" + sm.mentalDescription + "</p>\n" +
                    "                    <ul class=\"weui-media-box__info\">\n" +
                    "                        <li class=\"weui-media-box__info__meta\">截止时间</li>\n" +
                        "                        <li class=\"weui-media-box__info__meta\">" + closeDate + "</li>\n" +
                    "                        <li class=\"weui-media-box__info__meta weui-media-box__info__meta_extra\">" + operateStr + "</li>\n"
                    "                    </ul>\n" +
                    "                </div>";
                undoPanel.append(mText);
            }
        }
    });

</script>
</body>
</html>
